clc
clear all
close all

% 读取数据
filename = '12_4.csv';
table = readtable(filename);

%时间和数据分开保存
timestamps=table(:,2);
DataArray=table(:,3:end);
DataArray=table2array(DataArray); % 转化为数组

%% 控制组
C_ZZ203a = DataArray(:,218);
C_ZZ203b = DataArray(:,219);
C_ZZ208 = DataArray(:,322);
% 水
C_Doping_water = DataArray(:,315);
C_Return_Bin = DataArray(:,122);    %返料仓
C_Return_weight = DataArray(:,122);
C_CurrentA = DataArray(:,226);
C_CurrentB = DataArray(:,227);
C_SpeedSetA = DataArray(:,230);
C_SpeedSetB = DataArray(:,231);
C_BufferBin_A = DataArray(:,320);   % 缓冲仓
C_BufferBin_B = DataArray(:,321);
C_Total_weight = DataArray(:,45);
C_Scheme = DataArray(:,100:110);
C_Scheme_statue = zeros(length(DataArray),1);
C_Return_Bin_10min = zeros(length(DataArray),1);
C_CurrentA_1min = zeros(length(DataArray),1);
C_CurrentA_2min = zeros(length(DataArray),1);
C_CurrentA_3min = zeros(length(DataArray),1);
C_CurrentB_1min = zeros(length(DataArray),1);
C_CurrentB_2min = zeros(length(DataArray),1);
C_CurrentB_3min = zeros(length(DataArray),1);

% 粘结剂
C_Currentbinder = DataArray(:,58);
C_Return_Bin = DataArray(:,122);    %返料仓
% 速度
C_Return_Bin_10 = zeros(length(DataArray),1);    %返料仓10速度
C_Return_Bin_20 = zeros(length(DataArray),1);   %返料仓20速度
C_Return_Bin_30 = zeros(length(DataArray),1);    %返料仓30速度
% 加速度
C_Return_Bin_Access10 = zeros(length(DataArray),1);   %返料仓10加速度
C_Return_Bin_Access20 = zeros(length(DataArray),1);   %返料仓20加速度
C_Return_Bin_Access30 = zeros(length(DataArray),1);   %返料仓30加速度

C_BallRate = zeros(length(DataArray),1);
C_Total_weight = DataArray(:,45);
C_ReturnBin_speed = zeros(length(DataArray),1);
C_ReturnBin_ave = zeros(length(DataArray),1);
%% 建模组
M_Doping_water = DataArray(:,315);
M_Binder_weight = DataArray(:,123);
M_Return_weight = DataArray(:,122);
M_Actual_weight = DataArray(:,45);
M_Bufferbin_A = DataArray(:,320);
M_Bufferbin_B = DataArray(:,321);
M_ZZ203a = DataArray(:,218);
M_ZZ203b = DataArray(:,219);
M_Speed_a = DataArray(:, 228);
M_Speed_b = DataArray(:, 229);
M_Material_level_a = DataArray(:,222);
M_Material_level_b = DataArray(:,223);
M_ZF201 = DataArray(:,325);

%% 水
for i = 1:length(DataArray)
    if i <= 60
        C_BallRate(i) = C_ZZ208(i) ./ ((C_ZZ203a(i)+C_ZZ203b(i))*10E-4);
        C_BallRate(i) = 100*C_BallRate(i);
    else
        C_BallRate(i) = C_ZZ208(i) ./ ((C_ZZ203a(i-18)+C_ZZ203b(i-18))*10E-4);
        C_BallRate(i) = 100*C_BallRate(i);
        C_Scheme_statue(i) = ~isequal(C_Scheme(i,:),C_Scheme(i-12,:));
        C_Total_weightstatus = isequal(C_Total_weight(i),C_Total_weight(i-12));

    end
end
% 对成球率和分流分别进行预处理和滤波
    C_BallRate = SmoothFilter(C_BallRate,0.30,0.95,60);    %成球率滤波存在问题
    %压球电流
    C_CurrentA = WatersAndFilter(C_CurrentA,100,200,60,2);
    C_CurrentB = WatersAndFilter(C_CurrentB,100,200,60,2);

    %电流和返料仓趋势
    for i = 1:length(DataArray)
        %前10分钟单独考虑，数据前10分钟作废
        if i <= 120
            C_CurrentA_1min(i) = C_CurrentA(i)-C_CurrentA(1);
            C_CurrentA_2min(i) = C_CurrentA(i)-C_CurrentA(1);
            C_CurrentA_3min(i) = C_CurrentA(i)-C_CurrentA(1);
            C_CurrentB_1min(i) = C_CurrentB(i)-C_CurrentB(1);
            C_CurrentB_2min(i) = C_CurrentB(i)-C_CurrentB(1);
            C_CurrentB_3min(i) = C_CurrentB(i)-C_CurrentB(1);
            C_Return_Bin_10min(i) = (C_Return_Bin(i)-C_Return_Bin(1))./10;

           
        else
            C_CurrentA_1min(i) = C_CurrentA(i)-C_CurrentA(i-12);
            C_CurrentA_2min(i) = C_CurrentA(i)-C_CurrentA(i-24);
            C_CurrentA_3min(i) = C_CurrentA(i)-C_CurrentA(i-36);
            C_CurrentB_1min(i) = C_CurrentB(i)-C_CurrentB(i-12);
            C_CurrentB_2min(i) = C_CurrentB(i)-C_CurrentB(i-24);
            C_CurrentB_3min(i) = C_CurrentB(i)-C_CurrentB(i-36);
           
        end
    end

%% 粘结剂
% 5:此时的粘结剂量；
% 7-10:返料仓以及返料仓10、20、30分钟的速率；
% 11-12:返料仓10分钟-20分钟以及20分钟-30分钟产生的加速度；
% 13:修正后的成球率
% 26:新增的变量：总料位
% 28:新增的一个指标，用来形容返料仓变化快慢；
% 29:新增的一个指标，类似于返料仓加权平均值

% 返利仓速度与返料仓加速度
for i = 1:length(DataArray)
    if i <= 360
        C_Return_Bin_10(i) = 0;
        C_Return_Bin_20(i) = 0;
        C_Return_Bin_30(i) = 0;
        C_Return_Bin_Access10 = 0;
        C_Return_Bin_Access20 = 0;
        C_Return_Bin_Access30 = 0;
    else
        C_Return_Bin_10(i) = sum(C_Return_Bin(i-120:i))./120;
        C_Return_Bin_20(i) = sum(C_Return_Bin(i-240:i))./240;
        C_Return_Bin_30(i) = sum(C_Return_Bin(i-360:i))./360;
        C_Return_Bin_Access10(i) = sum(C_Return_Bin_10(i-120:i))./120;
        C_Return_Bin_Access20(i) = sum(C_Return_Bin_20(i-240:i))./240;
        C_Return_Bin_Access30(i) = sum(C_Return_Bin(i-360:i))./360;
    end
end

C_Return_Bin_Access10 = C_Return_Bin_Access10';
C_Return_Bin_Access20 = C_Return_Bin_Access20';
C_Return_Bin_Access30 = C_Return_Bin_Access30';

C_BallRate = SmoothFilter(C_BallRate,0.30,0.95,100);    %成球率滤波存在问题
C_Total_weight = C_Total_weight;
%返料仓指标
C_ReturnBin_speed = sign(C_Return_Bin_Access10)+sign(C_Return_Bin_Access20)+sign(C_Return_Bin_Access30)
C_ReturnBin_ave = (C_Return_Bin_10(:)+C_Return_Bin_20(:)+C_Return_Bin_30(:))./3;

for i = 1:length(DataArray)
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %控制组

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %建模组

end

   
